package com.example.bestudentsystem.demos.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.bestudentsystem.demos.web.pojo.Course;
import com.example.bestudentsystem.demos.web.pojo.Teacher;
import com.example.bestudentsystem.demos.web.vo.CourseVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TeacherMapper extends BaseMapper<Teacher> {

    // 根据教师ID获取教师教授的课程
    @Select("SELECT * FROM teacher JOIN course ON teacher.tno=course.tno WHERE teacher.tno=#{tno}")
    List<Course> getCourseByTno(String tno);

    @Update("UPDATE course \n" +
            "SET isopen = 0 \n" +
            "WHERE isopen = 3;")
    void resetIsOpenToZero();
    // 获取没有教授的课程（没有tno）
    @Select("SELECT course.cname, course.cno FROM course WHERE course.tno=00000 AND course.isopen=0")
    List<CourseVo> getNullCourse();

    // 更新课程名额和状态（apply状态）
    @Update("UPDATE course SET course.tno=#{tno}, course.residue=#{residue}, course.apply=#{apply} WHERE course.cname=#{cname}")
    void Update(String tno, int residue, int apply, String cname);

    // 获取某个教师所有的课程信息（包括已提交的申请）
    @Select("SELECT course.cno, course.cname, course.residue, course.isopen " +
            "FROM course " +
            "WHERE course.tno=#{tno} AND isopen=1")
    List<CourseVo> getAllCourseByTno(@Param("tno") String tno);
}
